{% extends 'base.html' %}
{% block head %}
    <link rel="stylesheet" href="{% static 'highlight/styles/github-dark.min.css' %}">
    <script src="{% static 'highlight/highlight.min.js' %}"></script>
{% endblock %}
{% block title %}
    {{ block.super }}-详情
{% endblock %}
{% block main %}

    <h1>{{ blog.title }}</h1>
    <hr>
    <div class="mt-2">
        <img class="rounded-circle" width="30px" height="30px" src="{% static 'image/avatar.webp' %}" alt="avatar">
        <span class="ms-2">{{ blog.author.username }}</span>
        <span class="ms-2">于</span>
        <span class="ms-2">{{ blog.pub_time|date:"Y年m月d日 H时i分s秒" }} 发布</span>
    </div>
    <hr>
    <div class="py-2">
        {{ blog.content|safe }}
    </div>
    <hr>
    <div class="mt-2">
        <h3>评论（{{ blog.comments.all|length }}条）</h3>
        <form action="{% url 'blog:pub_comment' %}" method="POST">
            {% csrf_token %}
            <input type="hidden" name="blog_id" value="{{ blog.id }}">
            <label class="mt-2">
                <input type="text" class="form-label" placeholder="清输入评论" name="content">
            </label><br>
            <div class="text-end">
                <button type="submit" class="btn btn-primary mt-2">评论</button>
            </div>
        </form>
    </div>
    <div class="mt-2">
        <ul class="list-group">
            {% for comment in blog.comments.all %}
                <li class="list-group-item">
                    {{ comment.content }}
                <li class="list-group-item mb-2">
                    <div class="d-flex justify-content-between text-body-secondary">
                        <div class="user-info">
                            <img src="{% static 'image/avatar.webp' %}" alt="avatar" class="rounded-circle" width="40px"
                                 height="40px">
                            <span class="ms-2">{{ comment.author.username }}</span>
                        </div>
                        <div class="create-time"
                             style="line-height: 40px">{{ comment.pub_time|date:"Y年m月d日 H时i分s秒" }}</div>
                    </div>
                    <div class="mt-2">{{ comment.content }}</div>
                </li>
            {% endfor %}
        </ul>
    </div>
    <script>
        hljs.highlightAll()();
    </script>
{% endblock %}